.PHONY: clean docker release test

# Modify this to match your own project
PROG=drone_go

RELEASE?=
REPO=registry.cn-hangzhou.aliyuncs.com/wise2c-dev
RLS_REPO=registry.cn-hangzhou.aliyuncs.com/wise2c-test
DEV_IMG=${REPO}/${PROG}:latest
RLS_IMG=${RLS_REPO}/${PROG}:${RELEASE}
TIME=`date +'%Y-%m-%d %H:%M:%S'`

default:
	go build -ldflags "-X 'main.gitCommit=`git rev-parse --short HEAD`' -X 'main.buildTime=$(TIME)' -X 'main.goVersion=`go version`'"

docker:
	echo $(TIME)
	docker build --label gitCommit=`git rev-parse --short HEAD` --build-arg gitCommit=`git rev-parse --short HEAD` --build-arg buildTime="$(TIME)" -t ${DEV_IMG} .
#	docker push ${DEV_IMG}

release:
ifeq ($(RELEASE),)
	@echo "RELEASE not defined!!!"
else
	docker build --label gitCommit=`git rev-parse --short HEAD` --build-arg gitCommit=`git rev-parse --short HEAD` --build-arg buildTime=$(TIME) -t ${RLS_IMG} -f Dockerfile.release .
	docker push ${RLS_IMG}
endif

clean:
	@rm $(PROG)

test:
	go test ./...

run:
	docker run -d --name drone_go ${DEV_IMG}